<template>
  <view>
    <c-navBar title="分校认证"></c-navBar>
    <view class="">
      <view class="cell flex flex-a flex-sb">
        <view class="flex">
          <view style="margin-top: 4px">
            <text class="is-required">*</text>
          </view>
          <view class="">
            <text class="label">学校</text>
          </view>
        </view>
        <text class="value">{{ extroInfo }}</text>
      </view>
    </view>
    <CForm
      extraHeight="103px"
      :formRules="formRules"
      v-model:formData="formData"
      :formList="formList"
      @submit="submit"
    ></CForm>
  </view>
</template>
<script setup>
import { ref } from "vue"
import CForm from "@/components/CForm/CForm.vue"
import {
  getSchoolAuthenticationData,
  AuthenticationSchool
} from "@/apis/school"

import { schoolAuthForm } from "./data"
const { formField, formList, formRules } = schoolAuthForm
const formData = ref(formField)
const extroInfo = ref("")
import { onLoad, onUnload, onBackPress } from "@dcloudio/uni-app"

let school_id = ""
let status = ""
onLoad((options) => {
  school_id = options.schoolId
  extroInfo.value = options.schoolName
  if (school_id) {
    getDetail()
  }
})

const getDetail = () => {
  getSchoolAuthenticationData({ school_id: school_id }).then((res) => {
    if (res.code === 1) {
      formData.value = res.data
    }
  })
}

const submit = () => {
  AuthenticationSchool({
    ...formData.value,
    school_id: school_id
  }).then((res) => {
    if (res.code === 1) {
      uni.showSuccessToast("提交认证成功！")
      setTimeout(() => {
        uni.navigateBack({
          delta: 1
        })
      }, 1500)
    }
  })
}
</script>

<style lang="scss" scoped>
.cell {
  border-radius: 6px;
  background: rgba(235, 235, 235, 1);

  border: 1px solid rgba(252, 247, 247, 1);
  margin: 80rpx 58rpx 30rpx;
  padding: 20rpx;
  font-size: 32rpx;
  .is-required {
    color: rgba(240, 2, 2, 1);
  }
  .label {
    color: rgba(0, 0, 0, 1);
    margin-left: 8rpx;
  }
  .value {
    color: rgba(102, 102, 102, 1);
  }
}
</style>
